package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao tDao = new TeacherDao();
    private Teacher[] ts = tDao.getAllTeacher();

    public Teacher[] showTeacher() {
        boolean flag=true;
        for (int i = 0; i < ts.length; i++) {
            Teacher t = ts[i];
            if (t != null) {
                flag=false;
                break;
            }
        }
        if (flag){
           return null;
        }else {
            return ts;
        }

    }

    public void addTeacher(Teacher teacher) {
        tDao.addTeacher(teacher);
    }

    public boolean isExists(String id) {

        boolean result = false;
        for (int i = 0; i < ts.length; i++) {
            Teacher t = ts[i];
            if (t != null && t.getId().equals(id)) {
                result = true;
            }
        }
        return result;
    }

    public void deleteTeacherById(String id) {
        tDao.deleteTeacherById(id);
    }

    public void updateTeacherById(Teacher t) {
        tDao.updateTeacher(t);
    }
}
